from rest_framework import serializers

from goods.models import SPUSpecification, SPU


# 商品规格表序列化器
class SpecSerializer(serializers.ModelSerializer):
    # 关联嵌套返回spu表的商品名
    spu = serializers.StringRelatedField(read_only=True)
    # 返回关联spu的id值
    spu_id = serializers.IntegerField()

    class Meta:
        model = SPUSpecification
        fields = ('id', 'name', 'spu', 'spu_id')

class SPUSeriallizer(serializers.ModelSerializer):
    """
        SPU商品表序列化器
    """
    class Meta:
        model=SPU
        fields=('id','name')